<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>构造函数实现封装以及问题</title>
</head>

<body>
  <script>
    // ============================== 构造函数实现封装，封装人的姓名、年龄和 sayHi方法 ==============================

    function Person(name,age) {
      this.name = name
      this.age = age
      this.sayHi = function(){
        console.log('hello') 
      }
    }

    // 实例化
    const zs = new Person('张三', 18)
    const ls = new Person('李四', 19)
    console.log(zs)
    console.log(ls)
    console.log(zs === ls)  //false 是2个对象
 
  // ============================== 构造函数实现封装有个小问题 ==============================
  console.log(zs.sayHi === ls.sayHi)  //false sayHi方法在内存中有2份（zs和ls各自否有一份sayHi方法）
  
  </script>
</body>

</html>